#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<random>
#include<ctime>

using namespace std;

class Arr
{
public:
	Arr(int n)
	{
		int* t = new int[n];
		_n = n;
		data = t;
		srand(time(NULL));
		for (int i = 0; i < n; i++)
		{
			data[i] = rand() % 1000;
		}
	}

	void disp()
	{
		for (int i = 0; i < _n; i++)
		{
			cout << data[i] << " ";
		}
		cout << endl;
	}

	void reverse()
	{
		for (int i = 0; i < _n / 2; i++)
		{
			swap(data[i], data[_n - i - 1]);
		}
	}

	void mergeSort(int* tmp,int begin,int end)
	{
		if (end - begin <= 1)
		{
			return;
		}
		int mid = (end-begin) / 2;
		mergeSort(tmp, begin, begin + mid);
		mergeSort(tmp, begin + mid, end);
		int pt = begin;
		int p1 = begin, p2 = begin + mid;

		while (p1 < begin + mid  && p2 < end && pt < end)
		{
			if (data[p1] > data[p2])
			{
				tmp[pt++] = data[p2++];
			}
			else
			{
				tmp[pt++] = data[p1++];
			}
		}

		if (p1 < begin + mid)
		{
			while (p1 < begin + mid )
			{
				tmp[pt++] = data[p1++];
			}
		}
			
		if (p2 < end)
		{
			while (p2 <  end)
			{
				tmp[pt++] = data[p2++];
			}
		}

		for (int i = begin; i < end; i++)
		{
			data[i] = tmp[i];
		}
	}


	void sort()
	{
		int* tmp = new int[_n];
		mergeSort(tmp,0, _n);
		int* t = data;
		delete[] t;
		data = tmp;
	}

	int search(int key)
	{
		for (int i = 0; i < _n; i++)
		{
			if (data[i] == key)
			{
				return i;
			}
		}
		return -1;
	}
private:
	int* data;
	int _n;
};

int main()
{
	int n;
	cin >> n;
	Arr tmp(n);

	tmp.disp();
	tmp.reverse();
	tmp.disp();

	tmp.sort();
	tmp.disp();

	cout << tmp.search(410) << endl;

	return 0;
}